/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.qp.smsmarketing.view.mbean;

import com.qp.smsmarketing.controller.LoginController;
import com.qp.smsmarketing.entity.Usuario;
import com.qp.smsmarketing.view.View;
import com.qp.smsmarketing.view.ViewIMEI;
import com.qp.smsmarketing.view.ViewLogin;
import com.qp.smsmarketing.view.ViewSobre;
import com.qp.smsmarketing.view.mbean.abstractmbean.AbstractMBean;

/**
 *
 * @author waldenilson
 */
public class LoginMBean extends AbstractMBean {

    private ViewLogin vLogin = null;
    private ViewIMEI vImei = null;
    
    public void exibirView(ViewLogin vl)
    {
        carregarView(vLogin,vl);
    }
    
    public void exibirView(ViewIMEI vimei)
    {
        carregarView(vImei,vimei);
    }
   
   public boolean verificarLogin(String user,String pass,View v)
   {
       boolean res = false;
       
       LoginController control = new LoginController();
       Usuario u = control.autenticarUsuario(user, pass);
       
       if(u != null)
       {
           if(!u.getLogUsuario().equals("gerarimei"))
           {
                v.getLbUsuario().setText("Usuário.: "+u.getNomeUsuario());
                if(u.getIdRoleUsuario()!=null && u.getIdRoleUsuario().getNomeRole()!=null)
                    v.getLbUsuario().setToolTipText(u.getIdRoleUsuario().getNomeRole());
                else
                    v.getLbUsuario().setToolTipText("Null");

                v.setName(u.getIdUsuario().toString());
                res = true;
           }
           else
           {
               exibirView(new ViewIMEI(v, true, v));
           }
       }
       return res;
   }
}
